function personInformAuth(){
    var name = $("#name").val();
    var idCard = $("#idCard").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryIdcardAndName",
        data:{
            name:name,
            idCard:idCard
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryBankCardAndName(){
    var name = $("#name").val();
    var idCard = $("#idCard").val();
    var bankNo = $("#bankNo").val();
    var phoneNo = $("#phoneNo").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryBankCardAndName",
        data:{
            name:name,
            idCard:idCard,
            bankNo:bankNo,
            phoneNo:phoneNo
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryAllNetPhoneInfo(){
    var name = $("#name").val();
    var idCard = $("#idCard").val();
    var phoneNo = $("#phoneNo").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryAllNetPhoneInfo",
        data:{
            name:name,
            idCard:idCard,
            phoneNo:phoneNo
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryOrgInfo(){
    var name = $("#name").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryOrgInfo",
        data:{
            name:name
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryOrgQualifications(){
    var name = $("#name").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryOrgQualifications",
        data:{
            name:name
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryOrgPenalty(){
    var name = $("#name").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryOrgPenalty",
        data:{
            name:name
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryOrgOwingTaxes(){
    var name = $("#name").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryOrgOwingTaxes",
        data:{
            name:name
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryOrgAbnormal(){
    var name = $("#name").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryOrgAbnormal",
        data:{
            name:name
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryOrgGenealogy(){
    var name = $("#name").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryOrgGenealogy",
        data:{
            name:name
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryJudgment(){
    var name = $("#name").val();

    $.ajax({
        url: WEB_ROOT+"/main/qryJudgment",
        data:{
            name:name
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            //从后台中获取到数据添加到树结构中
            if(data.flag == "success"){
                $("#retidContent").html(data.retMsg);
            }else{
                $("#retidContent").html(data.retMsg);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryLmzxCredit(){
    // var identityCardNo = $("#identityCardNo").val();
    // var identityName = $("#identityName").val();
    var username = $("#username").val();
    var password = $("#password").val();
    var middleAuthCode = $("#middleAuthCode").val();
    var uid = $("#uid").val();
    if(uid == undefined || uid.length == 0){
        uid = getUuid(32,16);
        $("#uid").val(uid);
    }

    $.ajax({
        url: WEB_ROOT+"/main/qryLmzxCredit",
        data:{
            // identityCardNo:identityCardNo,
            // identityName:identityName,
            username:username,
            password:password,
            middleAuthCode:middleAuthCode,
            uid:uid
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            if(data == undefined || data.code == undefined){
                $("#retidContent").html("查询失败!");
            }else if(data.code != "0010"){
                $("#retidContent").html(data.msg);
            }else{
                $("#token").val(data.token);
                $("#queryTimes").val("0");
                roundRobin(data.token,function(result){
                    //渲染结果
                    var html="";
                    html=LmzxCredithtml(result);
                    $("#retidContent").html(html);
                });
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function LmzxCredithtml(result){
    var html = "";
    if(result == undefined || result.length == 0){
        html += "没有查询到结果!"
        return html;
    }
    html += "<p >姓名："+result.basicInfo.name+"</p>";
    html += "<p >婚姻状态："+result.basicInfo.maritalStatus+"</p>";

    var creditRecordDivHtml = ""; //信贷记录
    creditRecordDivHtml += "<p class='title'>信贷记录</p>"
    var j, k,i;
    i=0;
    var a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
    var type=["信用卡","购房贷款","其他贷款","资产处置信息","保证人代偿信息"];
    var va=["账户数","未结清/未销户账户数","发生过逾期的账户数","发生过90天以上逾期的账户数","为他人担保笔数","笔数"];
    while(result.creditRecord.summary[i]!=undefined) {
        for (j =0; j<5; j++) {
            if (result.creditRecord.summary[i].type == type[j]) {
                for (k = 0; k <6; k++) {
                    if (result.creditRecord.summary[i].var == va[k]){
                        a[j+5*k]=result.creditRecord.summary[i].count;
                    }
                }
            }
        }
        i++;
    }
    creditRecordDivHtml += "<table class='creditRecord'><thead>"
        +"<tr>"
        +"<th>"+"&nbsp&nbsp&nbsp"+"</th>"
        +"<th>"+"&nbsp信用卡&nbsp"+"</th>"
        +"<th>"+"&nbsp购房贷款&nbsp"+"</th>"
        +"<th>"+"&nbsp其他贷款&nbsp"+"</th>"
        +"<th>"+"&nbsp资产处置信息&nbsp"+"</th>"
        +"<th>"+"&nbsp保证人代偿信息"+"</th>"
        +" </tr></thead>"
        + "<tbody>"
        +"<tr><td>"+"账户数："+"</td>"
        +"<td>&nbsp&nbsp"+a[0]+"</td>"
        +"<td>&nbsp&nbsp"+a[1]+"</td>"
        +"<td>&nbsp&nbsp"+a[2]+"</td>"
        +"<td>&nbsp&nbsp"+a[3]+"</td>"
        +"<td>&nbsp&nbsp"+a[4]+"</td>"
        +"</tr>"
        +"<tr><td>"+"未结清/未销户账户数："+"</td>"
        +"<td>&nbsp&nbsp"+a[5]+"</td>"
        +"<td>&nbsp&nbsp"+a[6]+"</td>"
        +"<td>&nbsp&nbsp"+a[7]+"</td>"
        +"<td>&nbsp&nbsp"+a[8]+"</td>"
        +"<td>&nbsp&nbsp"+a[9]+"</td>"
        +"</tr>"
        +"<tr><td>"+"发生过逾期的账户数："+"</td>"
        +"<td>&nbsp&nbsp"+a[10]+"</td>"
        +"<td>&nbsp&nbsp"+a[11]+"</td>"
        +"<td>&nbsp&nbsp"+a[12]+"</td>"
        +"<td>&nbsp&nbsp"+a[13]+"</td>"
        +"<td>&nbsp&nbsp"+a[14]+"</td>"
        +"</tr>"
        +"<tr><td>"+"发生过90天以上逾期账户数："+"</td>"
        +"<td>&nbsp&nbsp"+a[15]+"</td>"
        +"<td>&nbsp&nbsp"+a[16]+"</td>"
        +"<td>&nbsp&nbsp"+a[17]+"</td>"
        +"<td>&nbsp&nbsp"+a[18]+"</td>"
        +"<td>&nbsp&nbsp"+a[19]+"</td>"
        +"</tr>"
        +"<tr><td>"+"为他人担保笔数："+"</td>"
        +"<td>&nbsp&nbsp"+a[20]+"</td>"
        +"<td>&nbsp&nbsp"+a[21]+"</td>"
        +"<td>&nbsp&nbsp"+a[22]+"</td>"
        +"<td>&nbsp&nbsp"+a[23]+"</td>"
        +"<td>&nbsp&nbsp"+a[24]+"</td>"
        +"</tr>"
        +"<tr><td>"+"笔数："+"</td>"
        +"<td>&nbsp&nbsp"+a[25]+"</td>"
        +"<td>&nbsp&nbsp"+a[26]+"</td>"
        +"<td>&nbsp&nbsp"+a[27]+"</td>"
        +"<td>&nbsp&nbsp"+a[28]+"</td>"
        +"<td>&nbsp&nbsp"+a[29]+"</td>"
        +"</tr>"
        +"</tbody></table>";
    /******/
    i=0;
    j=0;
    while(result.creditRecord.detail[i]!=undefined) {

        creditRecordDivHtml += "<p class='subTitle'>"+qryundefined(result.creditRecord.detail[i].type) + "</p>";
        creditRecordDivHtml += "<p>"+qryundefined(result.creditRecord.detail[i].headTitle)+"</p>";
        creditRecordDivHtml += "<ol>";
        while(result.creditRecord.detail[i].item[j]!=undefined) {
            creditRecordDivHtml += "<li>"+qryundefined(result.creditRecord.detail[i].item[j])+ "</li>";
            j++;
        }
        creditRecordDivHtml += "</ol>";
        j=0;
        i++;
    }
    /*****/
    i=0;
    creditRecordDivHtml += "<p class='subTitle'>信贷记录备注：</p>"
    creditRecordDivHtml += "<ol>"
    while(result.creditRecord.comment[i]!=undefined) {
        creditRecordDivHtml += "<li>"+qryundefined(result.creditRecord.comment[i]) + "</li>";
        i++;
    }
    creditRecordDivHtml += "</ol>"

    html += "<div class='creditRecord'>"+creditRecordDivHtml+"</div>";
    /*****/
    var publicRecordDivHtml = "";
    publicRecordDivHtml += "<p class='title'>公共记录</p>";
    publicRecordDivHtml += "<p class='subTitle'>欠税记录：</p>";
    publicRecordDivHtml += "<ol>";
    i=0;
    while(result.publicRecord.taxArrearsRecords[i]!=undefined) {
        publicRecordDivHtml += "<li>"+qryundefined(result.publicRecord.taxArrearsRecords[i].taxOffice)
            +"&nbsp纳税人识别号："+qryundefined(result.publicRecord.taxArrearsRecords[i].taxpayNo)
            + "&nbsp欠税金额："+qryundefined(result.publicRecord.taxArrearsRecords[i].amt)
            + "&nbsp欠税统计时间:"+qryundefined(result.publicRecord.taxArrearsRecords[i].statisticalTime)+"</li>";
        i++;
    }
    publicRecordDivHtml += "</ol>";
    /****/
    i=0;
    publicRecordDivHtml += "<p class='subTitle'>民事判决记录：</p>";
    publicRecordDivHtml += "<ol>";
    while(result.publicRecord.civilJudgmentRecords[i]!=undefined) {
        publicRecordDivHtml += "<li>"+qryundefined(result.publicRecord.civilJudgmentRecords[i].executiveCourt)
            +"&nbsp案号："+qryundefined(result.publicRecord.civilJudgmentRecords[i].caseNo)
            + "&nbsp案由："+qryundefined(result.publicRecord.civilJudgmentRecords[i].caseCause)
            + "&nbsp立案时间:"+qryundefined(result.publicRecord.civilJudgmentRecords[i].filingTime)
            + "&nbsp诉讼标的:"+qryundefined(result.publicRecord.civilJudgmentRecords[i].actionObject)
            + "&nbsp诉讼标的金额:"+ qryundefined(result.publicRecord.civilJudgmentRecords[i].actionObjectAmt)
            + "&nbsp结案方式:"+ qryundefined(result.publicRecord.civilJudgmentRecords[i].closedWay)
            + "&nbsp调节/判决结果:"+ qryundefined(result.publicRecord.civilJudgmentRecords[i].judgmentResult)
            + "&nbsp调节/判决生效时间:"+qryundefined( result.publicRecord.civilJudgmentRecords[i].judgmentEffectTime)+"</li>";
        i++;
    }
    publicRecordDivHtml += "</ol>";
    /****/
    publicRecordDivHtml += "<p class='subTitle'>强制执行记录：</p>";
    publicRecordDivHtml += "<ol>";
    i=0;
    while(result.publicRecord.enforcementRecords[i]!=undefined) {
        publicRecordDivHtml += "<li>"+qryundefined(result.publicRecord.enforcementRecords[i].executiveCourt)
            + "&nbsp案号："+qryundefined(result.publicRecord.enforcementRecords[i].caseNo)
            + "&nbsp执行案由："+qryundefined(result.publicRecord.enforcementRecords[i].caseCause)
            + "&nbsp立案时间:"+qryundefined(result.publicRecord.enforcementRecords[i].filingTime)
            + "&nbsp申请执行标的:"+qryundefined(result.publicRecord.enforcementRecords[i].actionObject)
            + "&nbsp申请执行标的金额:"+qryundefined( result.publicRecord.enforcementRecords[i].actionObjectAmt)
            + "&nbsp结案时间:"+ qryundefined(result.publicRecord.enforcementRecords[i].closedTime)
            + "&nbsp结案方式:"+qryundefined( result.publicRecord.enforcementRecords[i].closedWay)
            + "&nbsp案件状态:"+qryundefined(result.publicRecord.enforcementRecords[i].caseStatus)
            + "&nbsp已执行标的:"+ qryundefined( result.publicRecord.enforcementRecords[i].executedObject)
            + "&nbsp已执行标的金额:"+qryundefined( result.publicRecord.enforcementRecords[i].executedObjectAmt)+"</li>";
        i++;
    }
    publicRecordDivHtml += "</ol>";

    /****/
    i=0;
    publicRecordDivHtml += "<p class='subTitle'>行政处罚记录：</p>";
    publicRecordDivHtml += "<ol>";
    while(result.publicRecord.administrativePenaltyRecords[i]!=undefined) {
        publicRecordDivHtml +="<li>"+ qryundefined(result.publicRecord.administrativePenaltyRecords[i].penaltyOffice)
            + "&nbsp文书编号："+qryundefined(result.publicRecord.administrativePenaltyRecords[i].basicNo)
            + "&nbsp处罚内容："+qryundefined(result.publicRecord.administrativePenaltyRecords[i].penaltyContent)
            + "&nbsp处罚金额:"+qryundefined(result.publicRecord.administrativePenaltyRecords[i].penaltyAmt)
            + "&nbsp处罚生效时间:"+qryundefined(result.publicRecord.administrativePenaltyRecords[i].penaltyEffectTime)
            + "&nbsp是否行政复议:"+qryundefined( result.publicRecord.administrativePenaltyRecords[i].isReview)
            + "&nbsp行政复议结果:"+ qryundefined(result.publicRecord.administrativePenaltyRecords[i].reviewResult)
            + "&nbsp处罚截止时间:"+qryundefined(result.publicRecord.administrativePenaltyRecords[i].penaltyEndTime)+"</li>";
        i++;
    }
    publicRecordDivHtml += "</ol>";

    /****/
    publicRecordDivHtml += "<p class='subTitle'>电信欠费信息：</p>";
    publicRecordDivHtml += "<ol>";
    i=0;
    while(result.publicRecord.telecomArrearsRecords[i]!=undefined) {
        publicRecordDivHtml += "<li>"+qryundefined(result.publicRecord.telecomArrearsRecords[i].telecomOperators)
            + "&nbsp业务类型："+qryundefined(result.publicRecord.telecomArrearsRecords[i].bizType)
            + "&nbsp记账年月："+ qryundefined(result.publicRecord.telecomArrearsRecords[i].accDate)
            + "&nbsp业务开通时间:"+qryundefined(result.publicRecord.telecomArrearsRecords[i].bizOpenDate)
            + "&nbsp欠费金额:"+qryundefined(result.publicRecord.telecomArrearsRecords[i].amt)+"</li>";
        i++;
    }
    publicRecordDivHtml += "</ol>";
    html += "<div class='publicRecord'>"+publicRecordDivHtml+"</div>";
    /****/
    i=0;
    j=0;
    var searchRecordDivHtml="";
    searchRecordDivHtml += "<p class='title'>查询记录</p>";
    //searchRecordDivHtml += "<p class='subTitle'>"+qryundefined(result.searchRecord.descrip)+"</p>";
    searchRecordDivHtml +="<ol>";
     while(result.searchRecord.searchRecordDet[i]!=undefined) {
         searchRecordDivHtml += "<p class='subTitle'>"+qryundefined(result.searchRecord.searchRecordDet[i].type)+"：</p>";
         while(result.searchRecord.searchRecordDet[i].item[j]!=undefined) {
             searchRecordDivHtml += "<li>"+
                 "&nbsp时间：" + qryundefined(result.searchRecord.searchRecordDet[i].item[j].time) +
                 "&nbsp查询用户：" + qryundefined(result.searchRecord.searchRecordDet[i].item[j].user) +
                 "&nbsp查询原因：" + qryundefined(result.searchRecord.searchRecordDet[i].item[j].reason) +"</li>";
             j++;
         }
         j=0;
         i++;
     }
    searchRecordDivHtml+= "</ol>";
    html += "<div class='publicRecord'>"+searchRecordDivHtml+"</div>";
    return html;
}

function qryundefined(txt){
    if(txt==undefined||txt==null){
        return "";
    }else{
        return txt;
    }
}

function roundRobin(token,resultRender) {
    var interval = setInterval(function () {
        var status = $("#status").val();
        var queryTimes = parseInt($("#queryTimes").val());
        var status = $("#status").val();
        //如果是以下情形，继续轮询
        if(status == undefined || status.length == 0 || status == "0100" || status == "0200"){
            //继续轮询，donothing here
            if (queryTimes > 20) {
                //如果轮询超过了20次，则终止轮询
                $("#retidContent").html("查询结果超时!");
                clearInterval(interval);
                return;
            }else{
                //如果轮询没有超过20次，则继续轮询，轮询累计次数+1
                $("#queryTimes").val(queryTimes + 1);
                qryLmzxStatus(token);
            }
        }else if(status == "0000"){
            //如果查询结果显示结果已生成，则查询结果，并停止轮询
            clearInterval(interval);
            qryLmzxResult(token,resultRender);
        }else {
            //查询结果显示异常，终止轮询
            clearInterval(interval);
        }
    }, 5000);
}

function qryLmzxHouseFund(){
    var areaCode = $("#area").val();
    // var identityCardNo = $("#identityCardNo").val();
    // var identityName = $("#identityName").val();
    var username = $("#username").val();
    var password = $("#password").val();
    var uid = $("#uid").val();
    if(uid == undefined || uid.length == 0){
        uid = getUuid(32,16);
        $("#uid").val(uid);
    }
    $.ajax({
        url: WEB_ROOT+"/main/qryHouseFund",
        data:{
            // P_identityCardNo:identityCardNo,
            // P_identityName:identityName,
            P_username:username,
            P_password:password,
            P_area:areaCode,
            P_uid:uid
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            if(data == undefined || data.code == undefined){
                $("#retidContent").html("查询失败!");
            }else if(data.code != "0010"){
                $("#retidContent").html(data.msg);
            }else{
                $("#token").val(data.token);
                $("#queryTimes").val("0");
                roundRobin(data.token,function(result){
                    var html = "";
                    html += "姓名："+result.name+"</br>";
                    html += "单位名称："+result.corpName+"</br>";
                    html += "余额："+result.bal+"</br>";
                    html += "月缴存："+result.monthlyDeposit+"</br>";
                    html += "月缴存基数："+result.baseDeposit+"</br>";
                    html += "账号状态："+result.accStatus+"</br>";

                    $("#retidContent").html(html);
                });
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qryLmzxStatus(token) {
    var bizType = $("#bizType").val();
    $.ajax({
        url: WEB_ROOT+"/main/qryLmzxStatus",
        data:{
            token:token,
            bizType:bizType
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            if(data == undefined){
                $("#retidContent").html("查询异常!");
            }else if(data.code == undefined || data.code.length == 0 || data.code == "0100" || data.code == "0200"){
                //以上状态需要继续轮询，msg信息不是最终信息不展示
                $("#status").val(data.code);
            }else {
                //这里包含成功和异常两种结果，这两种结果都要终止轮询，并展示最终信息
                $("#status").val(data.code);
                $("#retidContent").html(data.data);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
            console.log(JSON.stringify(XMLHttpRequest));
            console.log(JSON.stringify(textStatus));
            console.log(JSON.stringify(errorThrown));
        }
    });
}

function qryLmzxResult(token,resultRender) {
    var bizType = $("#bizType").val();
    $.ajax({
        url: WEB_ROOT+"/main/qryLmzxResult",
        data:{
            token:token,
            bizType:bizType
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (result){
            if(result == undefined || result.code == undefined){
                $("#retidContent").html("查询异常!");
            }else if(result.code != "0000"){
                $("#retidContent").html(result.msg);
            }else{
                resultRender(result.data);
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function getUuid(len, radix) {
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
    var uuid = [], i;
    radix = radix || chars.length;

    if (len) {
        // Compact form  
        for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
    } else {
        // rfc4122, version 4 form  
        var r;

        // rfc4122 requires these characters  
        uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
        uuid[14] = '4';

        // Fill in random data.  At i==19 set the high bits of clock sequence as  
        // per rfc4122, sec. 4.1.5  
        for (i = 0; i < 36; i++) {
            if (!uuid[i]) {
                r = 0 | Math.random()*16;
                uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
            }
        }
    }

    return uuid.join('');
}

/**
 * 查询社保
 */
function qrySocialSecurity(){
    // var identityCardNo = $("#identityCardNo").val();
    // var identityName = $("#identityName").val();
    var username = $("#username").val();
    var password = $("#password").val();
    var realName = $("#realName").val();
    var uid = $("#uid").val();
    var areaCode = $("#area").val();
    if(uid == undefined || uid.length == 0){
        uid = getUuid(32,16);
        $("#uid").val(uid);
    }

    $.ajax({
        url: WEB_ROOT+"/main/qrySocialSecurity",
        data:{
            // P_identityCardNo:identityCardNo,
            // P_identityName:identityName,
            P_username:username,
            P_password:password,
            P_uid:uid,
            P_area:areaCode
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            if(data == undefined || data.code == undefined){
                $("#retidContent").html("查询失败!");
            }else if(data.code != "0010"){
                $("#retidContent").html(data.msg);
            }else{
                $("#token").val(data.token);
                $("#queryTimes").val("0");
                roundRobin(data.token,function(result){
                    //渲染结果
                    var html = "";
                    html += "姓名："+result.name+"</br>";
                    html += "身份证号："+result.identityNo+"</br>";
                    html += "单位名称："+result.corpName+"</br>";
                    html += "账号状态："+result.accStatus+"</br>";
                    html += "养老：余额"+result.insurances[0].bal+"&nbsp;("+result.insurances[0].bal.accStatus+")"+"</br>";
                    html += "医疗：余额"+result.insurances[1].bal+"&nbsp;("+result.insurances[0].bal.accStatus+")"+"</br>";
                    $("#retidContent").html(html);
                });
            }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
            console.log(JSON.stringify(XMLHttpRequest));
            console.log(JSON.stringify(textStatus));
            console.log(JSON.stringify(errorThrown));

        }
    });
}

function qrySocialSecurityAreas() {
    $.ajax({
        url: WEB_ROOT+"/main/qrySocialSecurityAreas",
        data:{},
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            console.log(JSON.stringify(data));
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function qrySocialSecurityElem() {
    var areaCode = $("#area").val();
    $.ajax({
        url: WEB_ROOT+"/main/qrySocialSecurityElem",
        data:{
            areaCode:areaCode
        },
        type:"post",
        dataType:"json",
        async:true,
        cache:true,
        success: function (data){
            console.log(JSON.stringify(data));
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
        }
    });
}

function checkRequired() {
    var result = true;
    $("input.required").each(function (i,Object) {
        var value = $(this).val();
        if(value == undefined || value.length == 0 ){
            result = false;
            var labelText = $(this).closest("P").find("lable").text();
            alert(labelText+"不能为空!");
        }
    })
}
